#!/bin/sh
#
#

BUILDDATE=$(date +%F)

MAJORVERSION=`sed '/^\#/d' version.properties | grep 'major'  | tail -n 1 | sed 's/^.*=//;s/^[[:space:]]*//;s/[[:space:]]*$//'`
MINORVERSION=`sed '/^\#/d' version.properties | grep 'minor'  | tail -n 1 | sed 's/^.*=//;s/^[[:space:]]*//;s/[[:space:]]*$//'`

echo "Version: $MAJORVERSION.$MINORVERSION"
echo "Build date: $BUILDDATE"

BUILDDIR="yabetbuild"
BUILDNAME="yabet-win-$MAJORVERSION.$MINORVERSION"
RELEASEDIR="$BUILDDIR/$BUILDNAME"

echo "Build dir: $RELEASEDIR"

sed -i "s/%test-major-version%/$MAJORVERSION/g" yabetversion.cpp
sed -i "s/%test-minor-version%/$MINORVERSION/g" yabetversion.cpp
sed -i "s/%test-date%/$BUILDDATE/g" yabetversion.cpp

qmake yabet.pro -spec win32-x-g++ -r
make

svn revert yabetversion.cpp

rm -rf $RELEASEDIR
rm -rf $RELEASEDIR.zip

mkdir -p $RELEASEDIR
cp -rf release/yabet.exe $RELEASEDIR/

cp -rf build-libs/win/*.dll $RELEASEDIR/

mkdir $RELEASEDIR/markups
cp -rf markups/*.properties $RELEASEDIR/markups
cp -rf license $RELEASEDIR/
cp -rf changes $RELEASEDIR/

sed -i s/$/'\r'/ $RELEASEDIR/markups/*.properties
sed -i s/$/'\r'/ $RELEASEDIR/license
sed -i s/$/'\r'/ $RELEASEDIR/changes

cd $BUILDDIR
zip -r $BUILDNAME.zip $BUILDNAME

